import {createRoleToken, verifyToken} from "../middleware/JWTToken.js";
import {httpResult} from "../utils/utils.js";

export const getNewToken =  async (req, res) => {
    let id = req.headers['authorization'].split(" ")[2];
    let tokenObj = await createRoleToken(id);
    // console.log(tokenObj);
    res.json(httpResult.success(tokenObj));
};

export const checkToken = async (req, res) => {
    // 检查token是否有效，这里可以根据自己的需求进行实现
    let {id, token} = req.body;
    // console.log(id, token, "user");
    let result = await verifyToken(token, (data) => {
        return data.id.toString() === id.toString();
    });
    // console.log(result, 'checkToken');

    res.json(httpResult.success({result}));
};
